home *** CD-ROM | disk | FTP | other *** search
- Path: prodigy.com!usenet
- From: XKWR65B@prodigy.com (Mark Rubelmann)
- Newsgroups: comp.lang.c++
- Subject: Need help with PCX loader!
- Date: 9 Apr 1996 21:11:59 GMT
- Organization: Prodigy Services Company 1-800-PRODIGY
- Distribution: world
- Message-ID: <4kejqv$h9s@usenetw1.news.prodigy.com>
- NNTP-Posting-Host: innugap7-int.news.prodigy.com
- X-Newsreader: Version 1.2
-
- I was wondering if anyone had a clue as to what's wrong with this code.
- I've
- been messing around with this for several days now and I'm stumped. When
- this is executed, all it does is put a bunch of crap on the screen. I've
- left a few functions out of the code below. (Stuff like changing the
- video mode and
- palette routines) This program uses mode 13h, just so you know.. The
- problem is in one of these functions. Perhaps the _fmemcpy?? Anyway,
- here's the code:
- (BTW: This is my first try at classes..)
-
-
-
- #include <mem.h>
- #include <iostream.h>
- #include <fstream.h>
- #include <iomanip.h>
-
-
- unsigned char far *video_buffer = (char far *)0xA0000000L; // vram ptr
-
-
- typedef struct RGB_color_typ
- {
- unsigned char red; //Red component of color (0-63)
- unsigned char green; //Green component of color (0-63)
- unsigned char blue; //Blue component of color (0-63)
- } RGB_color, *RGB_color_ptr;
-
- typedef struct PCX_header_typ
- {
- char manufacturer; // Always 10
- char version; // 0-v2.5, 2-v2.8, 3-v2.8(Use def. pal), 5-v3.
- 0
- char encoding; // Always 1 (RLE)
- char bits_per_pixel; // Bits per pixel; in this case, 8.
- int xmin,ymin; // Upper left corner of image
- int xmax,ymax; // Size of image
- int hres; // # of pixels in X direction
- int vres; // # of pixels in Y direction
- char ega_pal[48]; // EGA palette.. Ignore it..
- char reserved; // Reserved
- char color_planes; // # of planes
- int bytes_per_line; // # of bytes per horiz line
- int palette_type; // Type of palette
- char filler[58]; // Filler
- } PCX_header;
-
- typedef struct PCX_struct_typ
- {
- PCX_header header; // 128 byte header
- unsigned char *image; // Decompressed image
- RGB_color palette[256]; // The palette
- } PCX_struct;
-
-
- class PCX_Class
- {
- public:
- int Load(char *filename, PCX_struct *pcx);
- void Show(PCX_struct *pcx);
- protected:
- ifstream infile;
- int InitPCX(char *filename, PCX_struct *pcx);
- void LoadPCX(PCX_struct *pcx);
- };
-
-
- // PCX_Class::Load - Main function to load PCXes
- int PCX_Class::Load(char *filename, PCX_struct *pcx)
- {
- if(InitPCX(filename, pcx)==1)
- return 1;
- else if(InitPCX(filename, pcx)==2)
- return 2;
- LoadPCX(pcx);
- return 0;
- } // End load
-
- int PCX_Class::InitPCX(char *filename, PCX_struct *pcx)
- {
- ifstream infile(filename, ios::in | ios::nocreate | ios::binary);
- if(infile.bad())
- return 1;
-
- if(!(pcx->image = new unsigned char [64000]))
- return 2;
-
- return 0;
- } // End InitPCX
-
- void PCX_Class::LoadPCX(PCX_struct *pcx)
- {
- unsigned char data, clrdat;
- int numbytes;
- unsigned int count=0;
-
- infile.istream::seekg(0L, ios::beg); // Goto begining of file
- infile >> pcx->header.manufacturer // Load the header
- >> pcx->header.version
- >> pcx->header.encoding
- >> pcx->header.bits_per_pixel
- >> pcx->header.xmin >> pcx->header.ymin
- >> pcx->header.xmax >> pcx->header.ymax
- >> pcx->header.hres >> pcx->header.vres
- >> pcx->header.ega_pal[48]
- >> pcx->header.reserved
- >> pcx->header.color_planes
- >> pcx->header.bytes_per_line
- >> pcx->header.palette_type
- >> pcx->header.filler[58];
-
- infile.istream::seekg(128L, ios::beg); // Start of RLE image data
- while(count<=64000)
- {
- infile >> data; // Get first piece o' data
- if(192<=data<=255) // Is it RLE?
- {
- numbytes=data-192; // # of bytes in run
- infile >> data; // Data for run
- while(numbytes>0)
- {
- pcx->image[count++] = data; // Copy the data numbytes
- times
- numbytes--;
- } // End while
- } // End if RLE
- else
- pcx->image[count++] = data; // If it's not RLE just copy the
- data
- } // End while count... blah blah blah...
-
- infile.istream::seekg(-768L,ios::end); // Go to begining of palette
- for(int color=0; color<256; color++) // Load palette
- {
- infile >> clrdat;
- clrdat >> 2;
- pcx->palette[color].red = clrdat;
-
- infile >> clrdat;
- clrdat >> 2;
- pcx->palette[color].green = clrdat;
-
- infile >> clrdat;
- clrdat >> 2;
- pcx->palette[color].blue = clrdat;
- } // End load pal
- } // End LoadPCX
-
- void PCX_Class::Show(PCX_struct *pcx)
- {
- _fmemcpy((char far *)video_buffer, pcx->image, 64000);
- }
-
- void main()
- {
- PCX_struct test;
- PCX_Class pcx;
-
- pcx.Load("test.pcx", &test); // TEST.PCX must be 320x200
- pcx.Show(&test);
- }
-
-
-
- Thanks! -Mark
-
-